package com.balabala.gym_user.controller.admin;

import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_user.pojo.entity.VipLevel;
import com.balabala.gym_user.service.VipLevelService;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 何涛
 * @Date: 2023/05/01/ 14:11
 * @description 会员等级相关接口
 */
@RestController
@RequestMapping("/admin/vipLevel")
@Api(tags = "会员等级后台接口")
@CrossOrigin
@Slf4j
public class VipLevelController {
    @Autowired
    VipLevelService vipLevelService;
    @PostMapping("/add")
    @ApiOperation("添加会员等级信息")
    public Result add(@RequestBody VipLevel vipLevel)
    {
        log.info("添加一条会员等级信息:{}",vipLevel);
        vipLevel.setDefaultUse((short) 1);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,vipLevelService.save(vipLevel));
    }

    @GetMapping("/findAll")
    @ApiOperation("查询所有会员等级信息")
    public Result findAll()
    {
        log.info("查询所有会员等级。。。");
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,vipLevelService.list());
    }

    @PutMapping("/update")
    @ApiOperation("更新会员等级信息")
    public Result update(@RequestBody VipLevel vipLevel)
    {
        log.info("修改一条会员等级信息：{}",vipLevel);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,vipLevelService.updateById(vipLevel));
    }

    @DeleteMapping("deleteById")
    @ApiOperation("根据id删除会员等级信息")
    public Result deleteById(@RequestParam Long id)
    {
        log.info("删除一条会员等级信息：{}",id);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,vipLevelService.removeById(id));
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查找会员等级信息")
    public Result findById(@PathVariable Long id)
    {
        log.info("根据id查找会员等级信息：{}",id);
        return Result.ok(ResultEnum.GENERALLY_SUCCESS,vipLevelService.getById(id));
    }
}
